﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Xml;
using System.IO;
using System.Net;
using System.Data.SqlClient;
using System.Xml.Linq;
using System.Data;
using System.Timers;

namespace FishbowlSynchronization
{
    static class Program
    {

        /*[STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        */

        static void Main(string[] args)
        {
            try
            {
                
                Config config = new Config();
                Fishbowl Fishbowl = new Fishbowl();
                DataUtility Utility = new DataUtility();
                String key = "";
                config.start();

                ConnectionObject connectionObject = new ConnectionObject();
                connectionObject = config.ReturnConnection();
                key = config.ReturnKey();
                string returnOrderSql = "select top 1 * from order_item_delivery_tbl " +
                                        "left join order_item_tbl on order_item_tbl.order_item_id = order_item_delivery_tbl.order_item_id " +
                                        "left join order_tbl on order_tbl.order_id = order_item_tbl.order_id " +
                                        "where order_tbl.order_id = 18000";
                string OrderSql_ContractInvoice = "select distinct order_tbl.order_id,CONVERT(VARCHAR(10),order_item_delivery_date,105) as order_item_delivery_date,order_date,order_item_delivery_location,order_item_delivery_invoice_number from order_item_delivery_tbl " +
                                         "left join order_item_tbl on order_item_tbl.order_item_id = order_item_delivery_tbl.order_item_id " +
                                         "left join order_tbl on order_tbl.order_id = order_item_tbl.order_id " +
                                         "where  order_item_delivery_invoice_number > 0 and order_item_delivery_id not in " +
                                         "(select order_item_delivery_id from order_item_delivery_fb_tbl)";
               /* string OrderSql_ContractInvoice = "select distinct order_tbl.order_id,CONVERT(VARCHAR(10),order_item_delivery_date,105) as order_item_delivery_date,order_date,order_item_delivery_location,order_item_delivery_invoice_number from order_item_delivery_tbl " +
                                         "left join order_item_tbl on order_item_tbl.order_item_id = order_item_delivery_tbl.order_item_id " +
                                         "left join order_tbl on order_tbl.order_id = order_item_tbl.order_id " +
                                         "where order_item_delivery_id > 428229 and order_item_delivery_invoice_number > 0 ";*/
                string OrderSql_VBInvoice = "select distinct order_item_delivery_type ,CONVERT(VARCHAR(10), order_item_delivery_date, 23) as deliverydate,order_item_delivery_location from order_item_delivery_tbl " +
                                            "left join order_item_delivery_type_tbl on order_item_delivery_type_tbl.order_item_delivery_id = order_item_delivery_tbl.order_item_delivery_id "+
                                            "where (order_item_delivery_tbl.order_item_delivery_date between  DATEADD(d,DATEDIFF(d,1,getdate()),0) and DATEADD(d,DATEDIFF(d,0,getdate()),0)) "+
                                            "and order_item_delivery_invoice_number = 0 and order_item_delivery_tbl.order_item_delivery_id not in " +
                                            "(select order_item_delivery_id from order_item_delivery_fb_tbl)" ;
                /*string OrderSql_VBInvoice = "select distinct order_item_delivery_type ,CONVERT(VARCHAR(10), order_item_delivery_date, 23) as deliverydate,order_item_delivery_location from order_item_delivery_tbl " +
                                            "left join order_item_delivery_type_tbl on order_item_delivery_type_tbl.order_item_delivery_id = order_item_delivery_tbl.order_item_delivery_id " +
                                            "where order_item_delivery_tbl.order_item_delivery_id > 431181 and order_item_delivery_invoice_number = 0 ";*/
               /* string OrderSql_VBInvoice = "select distinct order_item_delivery_type ,CONVERT(VARCHAR(10), order_item_delivery_date, 23) as deliverydate,order_item_delivery_location from order_item_delivery_tbl " +
                                          "left join order_item_delivery_type_tbl on order_item_delivery_type_tbl.order_item_delivery_id = order_item_delivery_tbl.order_item_delivery_id " +
                                          "where (order_item_delivery_type_tbl.order_item_delivery_id  between 235449 and 242812) " +
                                          "and order_item_delivery_invoice_number = 0 and order_item_delivery_tbl.order_item_delivery_id not in " +
                                          "(select order_item_delivery_id from order_item_delivery_fb_tbl)";*/
                 
                //string Sonumber = Utility.SaveSO(OrderSql_ContractInvoice, connectionObject, key);
                //string Sonumber = Utility.SaveSO1(OrderSql_VBInvoice, connectionObject, key);
                //Utility.SavePick(Fishbowl, connectionObject, key, Sonumber);
                //Utility.SaveShip(connectionObject, key, Sonumber+16);
                //Utility.SaveShip(connectionObject, key, "47","2012-07-26");
                
                //Utility.test(connectionObject, key, 47);

                //List<OrderStatus> OrderStatusList = Utility.StoreOrderStatus(connectionObject, key, "22");
                //3 600 000 ms= 1 hour 86 400 000 ms = 24 hour 30 mins = 1 800 000 ms 1 mins = 60000
                //Console.WriteLine(new TimeSpan(1, 0, 0, 0));
                //Console.WriteLine(new TimeSpan(0, 0, 0, 0, -1));
  
                 //everySecond = new System.Threading.Timer(o => Utility.returnOrderStatus(OrderStatusList),null, 0, 1000);
                //var start = new System.Threading.Timer(o => config.start(), null, 0, 2000000);

                //ExportProductTree
                //Product:Virgin
                
                //every10Second = new System.Threading.Timer(o => Utility.ExportProducts(connectionObject, key, "ExportProductTree", "Product:Virgin"), null, 0, 380000);
                //Utility.ExportProducts(connectionObject, key, "ExportProductTree", "Product:Virgin");
                //Utility.AddStock(connectionObject, key);
                //Utility.returnOrderStatus(OrderStatusList);
                Utility.returnSOList(connectionObject, key, "");
                //Utility.NextPurchaseDate(connectionObject, key);

                //everyHour = new System.Threading.Timer(o => Utility.ExportProducts(connectionObject, key, "ExportProductTree", "Product:Virgin"), null, 0, 86400000);
                //everyHour1 = new System.Threading.Timer(o => Utility.SaveSO(OrderSql_ContractInvoice, connectionObject, key), null, 0, 86400000);
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
      
    }
}

